package com.gxstnu.controller;

import com.github.pagehelper.PageInfo;
import com.gxstnu.common.Result;
import com.gxstnu.entity.Notice;
import com.gxstnu.entity.Notice;
import com.gxstnu.entity.Notice;
import com.gxstnu.service.NoticeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    NoticeService noticeService;

    @PostMapping("/add")
    public Result add(@RequestBody Notice notice){//@RequestBody接收前端json参数数据
        noticeService.add(notice);
        return Result.success();
    }
    @PutMapping ("/update")
    public Result update(@RequestBody Notice notice){//@RequestBody接收前端json参数数据
        noticeService.update(notice);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){//@PathVariable是前端传回来的路径参数
        noticeService.deleteById(id);
        return Result.success();
    }
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Notice> list){//@RquestBody 接收前端传来的 json数组
        noticeService.deleteBatch(list);
        return Result.success();
    }
    @GetMapping("/selectAll")
    public Result selectAll(Notice notice){
        List<Notice> noticeList = noticeService.selectAll(notice);
        return Result.success(noticeList);
    }
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize,
                             Notice notice) {
        PageInfo<Notice> noticePageInfo = noticeService.selectPage(pageNum, pageSize, notice);
        return Result.success(noticePageInfo);
    }
}
